package com.wss.lsl.lucene.demo.shipin.analyzer;

import java.io.Reader;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;

import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MaxWordSeg;
import com.chenlb.mmseg4j.analysis.MMSegTokenizer;
import com.wss.lsl.lucene.demo.shipin.filter.MySameTokenizerFilter;
import com.wss.lsl.lucene.demo.shipin.sameword.engine.SamewordContext;

// 自定义分词器
public class MySameAnalyzer extends Analyzer {
	
	private SamewordContext samewordContext;
	
	public MySameAnalyzer(SamewordContext samewordContext) {
		this.samewordContext = samewordContext;
	}

	@Override
	public TokenStream tokenStream(String fieldName, Reader reader) {
		Dictionary dic = Dictionary
				.getInstance("G:\\important\\apache\\mmseg\\mmseg4j-1.8.5\\data");

		return new MySameTokenizerFilter(new MMSegTokenizer(
				new MaxWordSeg(dic), reader), samewordContext);
	}

}
